﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace ivvIncorporadora
{
    public partial class deletarIVV : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string codigoIvvMax = Request["codigoIvv"].ToString();

                System.Data.SqlClient.SqlConnection sqlc = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                sqlc.Open();

                string sqlPegarL = "select * from ivv where codigoIvv = " + codigoIvvMax;

                System.Data.SqlClient.SqlCommand cmdPegarL = new System.Data.SqlClient.SqlCommand(sqlPegarL, sqlc);
                System.Data.SqlClient.SqlDataReader drPegarL = cmdPegarL.ExecuteReader();
                drPegarL.Read();

                string codigoEmpreendimento = drPegarL["codigoEmpreendimento"].ToString();
                string codigoTipoUnidadeEmpreendimento = drPegarL["codigoTipoUnidadeEmpreendimento"].ToString();

                cmdPegarL.Dispose();
                drPegarL.Close();

                string sqlDeletar = "delete from ivv where codigoIvv = " + codigoIvvMax + ";\n ";
                sqlDeletar += "delete from TipoUnidadeEmpreendimento where codigoTipoUnidadeEmpreendimento = " + codigoTipoUnidadeEmpreendimento + "; \n ";
                sqlDeletar += "delete from Empreendimento where codigoEmpreendimento = " + codigoEmpreendimento + ";\n";

                SqlCommand deletar = new SqlCommand(sqlDeletar, sqlc);
                deletar.ExecuteNonQuery();

                sqlc.Close();

                //mensagem java script
                string literalcc = "<script language=JavaScript>finalizar();</script>";
                pnlJS.Controls.Add(new LiteralControl(literalcc));
            }
            catch
            {
                //mensagem java script
                string literalcc = "<script language=JavaScript>finalizarErro();</script>";
                pnlJS.Controls.Add(new LiteralControl(literalcc));
            }
        }
    }
}
